# 手动安装 UiAutomator2 Server 到手机

Write-Host "============================================================" -ForegroundColor Cyan
Write-Host "手动安装 UiAutomator2 Server 到手机" -ForegroundColor Cyan
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host ""

# APK 路径
$apkPath = "C:\Program Files\Appium Server GUI\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks"

# 检查设备连接
Write-Host "1. 检查设备连接..." -ForegroundColor Yellow
$devices = adb devices
Write-Host $devices
Write-Host ""

# 安装 UiAutomator2 Server
Write-Host "2. 安装 UiAutomator2 Server..." -ForegroundColor Yellow
$apk1 = Join-Path $apkPath "appium-uiautomator2-server-v4.27.0.apk"

if (Test-Path $apk1) {
    Write-Host "   找到 APK: $apk1" -ForegroundColor Green
    Write-Host "   正在安装..."
    adb install -r -g $apk1
    Write-Host ""
} else {
    Write-Host "   ❌ 未找到 APK: $apk1" -ForegroundColor Red
}

# 安装 UiAutomator2 Server Test
Write-Host "3. 安装 UiAutomator2 Server Test..." -ForegroundColor Yellow
$apk2 = Join-Path $apkPath "appium-uiautomator2-server-debug-androidTest.apk"

if (Test-Path $apk2) {
    Write-Host "   找到 APK: $apk2" -ForegroundColor Green
    Write-Host "   正在安装..."
    adb install -r -g $apk2
    Write-Host ""
} else {
    Write-Host "   ❌ 未找到 APK: $apk2" -ForegroundColor Red
}

Write-Host "============================================================" -ForegroundColor Cyan
Write-Host "安装完成！" -ForegroundColor Green
Write-Host "现在可以运行: python test.py" -ForegroundColor Green
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host ""
Read-Host "按回车键退出"

